package com.heima.wemedia.controller.admin;

import com.heima.wemedia.service.ExcelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/excel")
@Slf4j
public class ExcelController {

    private final ExcelService excelService;

    public ExcelController(ExcelService excelService) {
        this.excelService = excelService;
    }

    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {
        excelService.exportExcel(response);
    }

    @PostMapping("/import")
    public String importExcel(@RequestParam("file") MultipartFile file) {
        excelService.importExcel(file);
        return "导入成功";
    }
}